<?php

namespace app\api\controller;

use think\Db;
use app\common\controller\Api;
use app\admin\model\Task;

class Taskapi extends Api
{

    protected $userId;

    /**
     * 我的任务
     */
    public function tasklist()
    {
        $params = $this->request->param();

        $page = $params['page'];

        $pageCount = $params['pageCount'];

        $task = new Task();
        $info = $task->getInfo(null,null,$this->userId,null,null,"state asc, weigh desc,id desc",$page,$pageCount);

        //总数
        $total = Task::where(['assign_id'=>$this->userId])->count();
        $result['total'] = $total;
        $result['info'] = $info;
        $result['pageTotal'] = count($info);
        $this->success('请求成功!!!',$result);
    }


    /**
     * 完成任务
     */
    public function completetask()
    {
        $params = $this->request->param();
        $id = $params['id'];
        $flag = Db::table('zc_task')->where('id', $id)->update(['state' => '1']);
        if($flag == 1){
            $this->success('成功!!!');
        }else{
            $this->error('请求失败!!!');
        }
    }

}
